/**
 * 
 */
package com.vivid.dynamics.oknow.model;

import java.util.HashSet;
import java.util.Set;

/**
 *
 * @author jason
 * created at:: Jul 27, 2011 5:04:23 PM
 */
public class Permission {
	private int id;
	//private int userId;
	private String permissions;
	private String name;
	private String descr;
	private User user;
	// set of bookmarks bounded by this permission
	private Set<Bookmark> bookmarks;
	
	/**
	 * ctor.
	 */
	protected Permission() {}
	
	/**
	 * ctor.
	 * @param permissions
	 * @param name
	 * @param descr
	 */
	public Permission(String permissions, String name, String descr) {
		super();
		//this.userId = userId;
		this.permissions = permissions;
		this.name = name;
		this.descr = descr;
	}

	/**
	 * <b>PS</b>. a MUST for hibernate entities, or you will have problems 
	 * during association methods; simply you can't remove / update the correct
	 * logical Entity in your collections<p/>
	 * 
	 * <b>PS</b>. due to some unknown reasons... the hashCode's components 
	 * would only consists of the "id" field(s) instead of all available 
	 * fields.
	 * <p/>
	 * {@inheritDoc}
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		/*
		result = prime * result + ((descr == null) ? 0 : descr.hashCode());		
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result
				+ ((permissions == null) ? 0 : permissions.hashCode());
		 */
		return result;
	}

	/**
	 * <b>PS</b>. a MUST for hibernate entities, or you will have problems 
	 * during association methods; simply you can't remove / update the correct
	 * logical Entity in your collections<p/>
	 * <b>PS</b>. due to some unknown reasons... the hashCode's components 
	 * would only consists of the "id" field(s) instead of all available 
	 * fields.<p/>
	 * {@inheritDoc}
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		
		if (!(obj instanceof Permission)) {
			return false;
		}
		/*if (getClass() != obj.getClass())
			return false;*/
		
		Permission other = (Permission) obj;		
		if (id != other.id)
			return false;
		
		if (descr == null) {
			if (other.descr != null)
				return false;
		} else if (!descr.equals(other.descr))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (permissions == null) {
			if (other.permissions != null)
				return false;
		} else if (!permissions.equals(other.permissions))
			return false;
		
		return true;
	}

	/**
	 * 
	 */
	@Override
	public String toString() {
		return "Permission [id=" + id + ", permissions="
			+ permissions + ", name=" + name + ", descr=" + descr + "]";
	}
	

	/* ********************** */
	/* *  accessor/mutator  * */
	/* ********************** */
	
	/*
	 * 
	 * @return
	 * @author jason
	 * created at:: Jul 27, 2011  5:06:14 PM
	 *
	public int getUserId() {
		return userId;
	}
	public void setUserId(int userId) {
		this.userId = userId;
	}*/

	/**
	 * 
	 * @return
	 * @author jason
	 * created at:: Jul 27, 2011  5:06:43 PM
	 */
	public String getPermissions() {
		return permissions;
	}
	public void setPermissions(String permissions) {
		this.permissions = permissions;
	}

	/**
	 * 
	 * @return
	 * @author jason
	 * created at:: Jul 27, 2011  5:06:48 PM
	 */
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * 
	 * @return
	 * @author jason
	 * created at:: Jul 27, 2011  5:06:53 PM
	 */
	public String getDescr() {
		return descr;
	}
	public void setDescr(String descr) {
		this.descr = descr;
	}

	/**
	 * 
	 * @return
	 * @author jason
	 * created at:: Jul 27, 2011  5:06:59 PM
	 */
	public int getId() {
		return id;
	}
	protected void setId(int pId) {
		this.id=pId;
	}

	/**
	 * 
	 * @return
	 * @author jason
	 * created at:: Jul 28, 2011  11:27:56 AM
	 */
	public User getUser() {
		return user;
	}
	protected void setUser(User user) {
		this.user = user;
	}
	
	/**
	 * 
	 * @return
	 * @author jason
	 * created at:: Jul 28, 2011  11:33:07 AM
	 */
	public Set<Bookmark> getBookmarks() {
		if (this.bookmarks==null) {
			this.bookmarks=new HashSet<Bookmark>();
		}
		return bookmarks;
	}
	protected void setBookmarks(Set<Bookmark> bookmarks) {
		this.bookmarks = bookmarks;
	}
	
}
